##| include: false
#| echo: false
#| fig-width: 6
#| fig-height: 4.2
# Load data
pop_data <- readRDS("data/pop_change.rds")
state_geom <- readRDS("data/state_geom.rds")
# Create static plot
plot_demo <- ggplot(pop_data, aes(fill = pop_category)) +
geom_sf_interactive(
aes(tooltip = tooltip, data_id = NAME),
color = "white",
linewidth = 0.1
) +
geom_sf(
data = state_geom,
color = "gray50",
fill = NA,
linewidth = 0.3
) +
scale_fill_manual(values = c("gray", "#8c510a","#bf812d", "#dfc27d","#f6e8c3", "#c7eae5","#80cdc1","#35978f", "#01665e")) +
scale_x_continuous(expand = expansion(mult = c(0.02, 0.14))) +
labs(
title = "U.S. County Population Changes: 2019-2023",
caption = "Data: U.S. Census Bureau\nViz: Tim Fulton, PhD"
) +
theme_void() +
theme(
plot.background = element_rect(fill = "white", color = "white"),
plot.title = element_text(size = 13, face = "bold", hjust = 0.5, margin = margin(b = 2)),
plot.caption = element_text(size = 7, color = "black", face = "italic", hjust = 0.02),
legend.title = element_blank(),
legend.key.size = unit(0.25, "cm"),
legend.text = element_text(size = 7),
legend.position = "inside",
legend.position.inside = c(0.91, 0.32)
) +
guides(fill = guide_legend(reverse = TRUE))
# Render interactive plot
girafe(ggobj = plot_demo) %>%
girafe_options(
opts_hover(css = "fill:black;"),
opts_toolbar(saveaspng = FALSE)
)